import axios from '@/utils/request'

/**
 * 获取用户个人信息---粉丝，关注等
 * @returns
 */
export const getUserInfoAPI = () => axios({
  url: '/v1_0/user'
})

/**
   * 获取用户个人信息---生日等
   * @returns
   */
export const getProfileAPI = () => axios({
  url: '/v1_0/user/profile'
})

/**
   * 修改用户头像
   */
export const editUserPhoto = (fd) => axios({
  url: '/v1_0/user/photo',
  method: 'PATCH',
  // Content-Type为multipart/form-data不需要自己写,
  // 只要让"请求体是FormData类型(new FormData())的",
  // 浏览器会自动修改Content- Type为multipart / form - data
  data: fd
})

/**
   * 编辑用户资料，传入什么，修改什么
   * @param {*} param0
   * @returns
   */
export const editUserInfoAPI = ({ name = null, gender = null, birthday = null, real_name = null, intro = null }) => {
  const obj = {}
  if (name !== null) {
    obj.name = name
  }
  if (gender !== null) {
    obj.gender = gender
  }
  if (birthday !== null) {
    obj.birthday = birthday
  }
  if (real_name !== null) {
    obj.real_name = real_name
  }
  if (intro !== null) {
    obj.intro = intro
  }
  return axios({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: obj
  })
}

/**
   * 刷新用户token
   * @returns
   */
export const refreshTokenAPI = () => axios({
  url: '/v1_0/authorizations',
  method: 'PUT',
  headers: {
    Authorization: 'Bearer ' + localStorage.getItem('refresh_token')
  }
})
